<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes">
<title>会员注册</title>
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<link rel="stylesheet" type="text/css" href="/static/css/shoujisc.css">
<script type="text/javascript" src="/static/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="/static/js/myinit.js"></script>
<style type="text/css">
.sczc-ul1 li {
	line-height: 44px;
	height: 44px;
}
.sczc-ul1 li .sczc-ipt1 {
	height: 44px
}
</style>
</head>

<body style="background:#fff;">
<div id="huiyuanka" style="display:none;"> <img src="/static/img/huiyuanka.jpg" width="100%" height="auto"/>
	<button class="sczc-btn1" style="height:40px;margin-top:40px"  id="diancixiaogai">点此修改</button>
	
	<div style="border:#0F0 1px solid;height:36px;line-height:36px;text-align:center;margin-top:30%;margin-left:3%;margin-right:3%;font-size:14px;border-radius:5px;color:rbg(158,158,158)">查看会员礼遇</div>
	
	
	<div style="position:fixed;bottom:0px;width:100%">
	
	   <div style="width:100%;font-size:12px;"><div style="display:inline-block;width:25%;text-align:center;height:50px;line-height:50px"><img src="/static/img/duo.png" style="display: inline-block; vertical-align: middle;  " height="20px" width="auto">品类齐全</div><div style="display:inline-block;width:25%;text-align:center;height:50px;line-height:50px"><img src="/static/img/kuai.png" style="display: inline-block; vertical-align: middle;  " height="20px" width="auto">多仓直发</div><div style="display:inline-block;width:25%;text-align:center;height:50px;line-height:50px"><img src="/static/img/hao.png" style="display: inline-block; vertical-align: middle;  " height="20px" width="auto">正品行货</div><div style="display:inline-block;text-align:center;height:50px;line-height:50px;width:25%;"><img src="/static/img/sheng.png" style="display: inline-block; vertical-align: middle;  " height="20px" width="auto">天天低价</div></div>
        
       
        
        
        
		<hr style="border-bottom:0px;border-color: rgba(180, 189, 99,0.3);margin-top:0px;margin-bottom:0px">
		
		<div style="text-align:center;background-image:url('/static/img/tiantianhuiwang.png');background-position:center;background-repeat:no-repeat;background-size:auto 50px;height:50px;background-color: #F7F7F7;"><div></div></div>
		
		</div>
		
	
</div>
<div style="display:none" id="mainbody">
	<ul class="sczc-ul1">
		<li>
			<p class="sczc-p1 f-l"><img src="/static/img/name.png" id="nameimg">用户名</p>
			<input type="text" placeholder="请输入用户名/昵称/邮箱" class="sczc-ipt1 f-l" maxlength="32" id="username"/>
			<div style="clear:both;"></div>
		</li>
		<li>
			<p class="sczc-p1 f-l"><img src="/static/img/phone.png" id="phoneimg">手机号</p>
			<input type="tel" placeholder="请输入手机号" id="telephone" maxlength="11" class="sczc-ipt1 f-l" />
			<!--
            <a id="getyzm"  class="sczc-a1 f-r" style="margin-top:8px;margin-right:3px;">获取验证码</a>
            -->
			<div style="clear:both;"></div>
		</li>
		<li id="oldpassword_body" style="display:none">
			<p class="sczc-p1 f-l"><img src="/static/img/mima.png" id="oldpasswordimg">旧密码</p>
			<input type="password" placeholder="请输入旧密码" id="oldpassword" maxlength="6"  class="sczc-ipt1 f-l" />
			<div style="clear:both;"></div>
		</li>
		<li>
			<p class="sczc-p1 f-l"><img src="/static/img/mima.png" id="passwordimg"><span id="xinmima">密<span style="visibility:hidden">您</span>码</span></p>
			<input type="password" placeholder="请输入密码" id="password" maxlength="6"  class="sczc-ipt1 f-l" />
			<div style="clear:both;"></div>
		</li>
		<li>
			<p class="sczc-p1 f-l"><img src="/static/img/mima.png" id="password_cmfimg">请确认</p>
			<input type="password" placeholder="再次输入密码" id="password_cmf" maxlength="6"  class="sczc-ipt1 f-l" />
			<div style="clear:both;"></div>
		</li>
		
		<!--
    	<li>
        	<p class="sczc-p1 f-l"><img src="/static/img/sjsc-12-4.png">验证码</p>
            <input type="text" id="yzm" placeholder="请输入验证码" maxlength="6" class="sczc-ipt1 f-l" />
            <div style="clear:both;"></div>
        </li>
        -->
	</ul>
	<button class="sczc-btn1" style="height:40px"   id="cmf">注册</button>
	<div class="sczc-ty">
		<label>
			<input type="checkbox" id="allreadyread">
			<a href="#">已阅读用户服务与协议</a> </label>
	</div>
</div>
<script type="text/javascript">
	$('#username').on('focusin',function(){
		$('#nameimg').attr('src','/static/img/name_focus.png');
	});
	$('#username').on('focusout',function(){
		$('#nameimg').attr('src','/static/img/name.png');
	});
	
	
	$('#telephone').on('focusin',function(){
		$('#phoneimg').attr('src','/static/img/phone_focus.png');
	});
	$('#telephone').on('focusout',function(){
		$('#phoneimg').attr('src','/static/img/phone.png');
	});
	
	
	$('#oldpassword').on('focusin',function(){
		$('#oldpasswordimg').attr('src','/static/img/mima_focus.png');
	});
	$('#oldpassword').on('focusout',function(){
		$('#oldpasswordimg').attr('src','/static/img/mima.png');
	});
	
	$('#password').on('focusin',function(){
		$('#passwordimg').attr('src','/static/img/mima_focus.png');
	});
	$('#password').on('focusout',function(){
		$('#passwordimg').attr('src','/static/img/mima.png');
	});
	
	
	$('#password_cmf').on('focusin',function(){
		$('#password_cmfimg').attr('src','/static/img/mima_focus.png');
	});
	$('#password_cmf').on('focusout',function(){
		$('#password_cmfimg').attr('src','/static/img/mima.png');
	});
	
	
	 
	var openid=getUrldata('OPENID');
	var url_zhuce="/webserver/api/v1/user/";
	
	var last=null;
	
	
	function initZhuce(){
		var url = "/webserver/api/v1/user/?format=json&openid="+openid;
		$.getJSON(url,function(rs){
			var objects = rs.objects;
			if(objects.length>0){
				/*{"active_at"
: "", "address": "", "balance": "0.00", "city": "", "headimgurl": null, "id": 13, "is_active": false
, "latitude": "", "longitude": "", "modify_at": "2016-08-21T14:11:09", "nickname": "xujian", "openid"
: "XTTTTTTTTTTTTT", "password": "1234567", "precision": "", "province": "", "score": "0.00", "sex": "2"
, "subscribe_time": "", "telephone": "12345678888"}*/
				var 	aa=objects[0];
				last=aa;
				$('#telephone').val(aa.telephone);
				$('#username').val(aa.nickname);
				
				url_zhuce="/webserver/api/v1/user/"+aa.id+"/";
				$('#cmf').html('确认修改');
				$('#oldpassword_body').show();
				
				$('#xinmima').html('新密码');
				$('#password').attr('placeholder','请输入新密码');
				 
				$('#cmf').click(function(e) {
					update();
				});
				$('#mainbody').hide();
				$('#huiyuanka').show();
				$('#diancixiaogai').click(function(e) {
					$('#mainbody').show();
					$('#huiyuanka').hide();
				});
				
				
			}else{
				$('#mainbody').show();
				$('#huiyuanka').hide();
				$('#cmf').click(function(e) {
					zhuce();
				});
			}
		});
	
	}
	
	
	$(document).ready(function(e) {
		initZhuce();
	});
	
	
	
	
	/*
	$('#getyzm').click(function(e) {
		yzm="123456";
	});
	*/
	
	
	function zhuce(){
		if(!$('#allreadyread').is(':checked')){
			alert('尚未阅读用户服务与协议');
			return ;
		}
		
		var aa={};
		aa.openid=openid;
		aa.nickname=$('#username').val();
		if(aa.nickname.length<2){
			alert('用户名太短');
			return;
		}
		aa.password=$('#password').val();
		if(aa.password.length<6){
			alert('密码太短');
			return;
		}
		
		if(aa.password!=$('#password_cmf').val()){
			alert('俩次密码输入不一致');
			return;
		}
		if(aa.password.length!=6){
			alert('密码必须为6位数');
			return;
		}
		aa.telephone=$('#telephone').val();
		if(aa.telephone.length!=11){
			alert('手机号不正确');
			return;
		}
		dopost(url_zhuce,aa,function(rs){
			console.log(rs);
			if(rs.id!=''&&rs.id!=undefined&&rs.id !=null&&rs.id !='null'){
				alert("注册成功");
				document.location.href=document.location.href;
			}
		});
	}
	
	
	
	function update(){
		if(!$('#allreadyread').is(':checked')){
			alert('尚未阅读用户服务与协议');
			return ;
		}
		
		var aa={};
		aa.openid=openid;
		aa.nickname=$('#username').val();
		if(last==null){
			alert('非法页面');
			return;
		}
		
		var old_password=$('#oldpassword').val();
		
		
		if(last.password!=''&&last.password!=undefined&&last.password !=null&&last.password !='null'){
			if(last.password!=old_password){
			
				alert('旧密码错误');
			
				return;
			}
		
		}
		
		if(aa.nickname.length<2){
			alert('用户名太短');
			return;
		}
		aa.password=$('#password').val();
		if(aa.password.length<6){
			alert('密码太短');
			return;
		}
		if(aa.password.length!=6){
			alert('密码必须为6位数');
			return;
		}
		if(aa.password!=$('#password_cmf').val()){
			alert('俩次密码输入不一致');
			return;
		}
		aa.telephone=$('#telephone').val();
		if(aa.telephone.length!=11){
			alert('手机号不正确');
			return;
		}
		doput(url_zhuce,aa,function(rs){
			if(rs.id!=''&&rs.id!=undefined&&rs.id !=null&&rs.id !='null'){
				alert("修改成功");
				$('#mainbody').hide();
				$('#huiyuanka').show();
			}
		
		});
	
	}
	
	$('#todenglu').click(function(){
		document.location.href="denglu.html?OPENID="+openid;
	});
	</script>
</body>
</html>
